<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <home></home>
  </div>
  <script src="./vue.js"></script>
  <script>
    const CommonTitle = {
      template: `
        <div>
          <h3>这是子组件</h3>  
          <button @click="emit">点击传给父组件一个数据</button>
        </div>
      `,
      data(){
        return {
          msg: '这是子组件中的数据'
        }
      },
      methods: {
        emit(){
          // 代码触发 事件触发一次
          this.$emit('biubiubiu', this.msg)
        }
      }
    }
    Vue.component('Home', {
      template: `
        <div>
         <h2>父组件</h2>
         {{ msg }}
          <hr/>
          <common-title @biubiubiu="fn"></common-title>
        </div>
      `,
      data(){
        return {
          msg: ''
        }
      },
      methods: {
        fn(msg){
          this.msg = msg;
        }
      },
      components: {
        CommonTitle
      }
    })
    const vm = new Vue({
      el: '#app'
    })
  </script>
</body>
</html>